<?php
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| This file is where you may define all of the routes that are handled
| by your application. Just tell Laravel the URIs it should respond
| to using a Closure or controller method. Build something great!
|
*/

Route::redirect('/admin', '/admin/login');

//公开的渲染
Route::group(['namespace' => 'Admin\View','prefix'=>'admin'], function() {
    Route::get('login', 'LoginController@index');
});

//公开的API
Route::group(['namespace' => 'Admin\Api','prefix'=>'admin/api'], function() {
    Route::post('login', 'LoginController@login')->name('admin.login');
});

//需要登录的api路由
Route::group(['namespace' => 'Admin\Api','prefix'=>'admin/api','middleware' => ['auth']], function() {

    Route::post('/upload', 'UploadController@upload');
    Route::get('logout', 'LoginController@logout')->name('admin.logout');

    //地区
    Route::get('regions/{parent_id}', 'RegionController@lists')->where('parent_id','[0-9][0-9]*');

    //菜单管理
    Route::post('permission', 'PermissionController@store');
    Route::get('permissions', 'PermissionController@page');
    Route::put('permission/{id}/state/{state}', 'PermissionController@state')->where('id','[1-9][0-9]*')->where('state','[0-1]');
    Route::delete('permission/{id}', 'PermissionController@delete')->where('id','[1-9][0-9]*');
    Route::put('permission/{id}', 'PermissionController@update')->where('id','[1-9][0-9]*');

    //品牌管理
    Route::post('brand', 'BrandController@store');
    Route::get('brands', 'BrandController@page');
    Route::put('brand/{id}/state/{state}', 'BrandController@state')->where('id','[1-9][0-9]*')->where('state','[0-1]');
    Route::delete('brand/{id}', 'BrandController@delete')->where('id','[1-9][0-9]*');
    Route::put('brand/{id}', 'BrandController@update')->where('id','[1-9][0-9]*');
    Route::get('brands/{id}', 'BrandController@tree')->where('id','[0-9]*');

    //产品管理
    Route::post('product', 'ProductController@store');
    Route::get('products', 'ProductController@page');
    Route::put('product/{id}/state/{state}', 'ProductController@state')->where('id','[1-9][0-9]*')->where('state','[0-1]');
    Route::delete('product/{id}', 'ProductController@delete')->where('id','[1-9][0-9]*');
    Route::put('product/{id}', 'ProductController@update')->where('id','[1-9][0-9]*');
    Route::get('product/pl', 'ProductController@pl');

    //产品管理
    Route::post('product_site', 'ProductSiteController@store');
    Route::get('product_sites', 'ProductSiteController@page');
    Route::delete('product_site/{id}', 'ProductSiteController@delete')->where('id','[1-9][0-9]*');
    Route::put('product_site/{id}', 'ProductSiteController@update')->where('id','[1-9][0-9]*');

    //角色管理
    Route::post('role', 'RoleController@store');
    Route::get('roles', 'RoleController@page');
    Route::delete('role/{id}', 'RoleController@delete')->where('id','[1-9][0-9]*');
    Route::put('role/{id}', 'RoleController@update')->where('id','[1-9][0-9]*');
    //给角色设置权限
    Route::post('role/{id}/permission', 'RoleController@permission')->where('id','[1-9][0-9]*');

    //用户管理
    Route::post('user', 'UserController@store');
    Route::get('users', 'UserController@page');
    Route::delete('user/{id}', 'UserController@delete')->where('id','[1-9][0-9]*');
    Route::put('user/{id}', 'UserController@update')->where('id','[1-9][0-9]*');
    Route::put('user/{id}/job/{state}', 'UserController@job')->where('id','[1-9][0-9]*')->where('state','[0-1]');
    //设置角色
    Route::post('user/{id}/role', 'UserController@role')->where('id','[1-9][0-9]*');

});


//必须要登录的渲染路由 'middleware' => ['admin.auth']
Route::group(['namespace' => 'Admin\View','prefix'=>'admin','middleware' => ['auth']], function() {
    Route::get('layout', 'HomeController@layout');
    Route::get('body', 'HomeController@body');

    //菜单管理
    Route::get('permission', 'PermissionController@index')->name('admin.permission');
    Route::get('permission/{id}', 'PermissionController@update')->where('id','[1-9][0-9]*');
    Route::get('{pid}/permission', 'PermissionController@store')->where('pid','[0-9]*');

    //品牌管理
    Route::get('brands', 'BrandController@index');
    Route::get('brand/{id}', 'BrandController@update')->where('id','[1-9][0-9]*');
    Route::get('{pid}/brand', 'BrandController@store')->where('pid','[0-9]*');

    //角色管理
    Route::get('roles', 'RoleController@index')->name('admin.role');
    Route::get('role/{id}', 'RoleController@update')->where('id','[1-9][0-9]*');
    Route::get('role', 'RoleController@store');

    //产品管理
    Route::get('products', 'ProductController@index');
    Route::get('product/{id}', 'ProductController@update')->where('id','[1-9][0-9]*');
    Route::get('product', 'ProductController@store');

    //产品管理
    Route::get('product_sites', 'ProductSiteController@index');
    Route::get('product_site/{id}', 'ProductSiteController@update')->where('id','[1-9][0-9]*');
    Route::get('product_site', 'ProductSiteController@store');

    //给角色设置权限
    Route::get('role/{id}/permission', 'RoleController@permission')->where('id','[1-9][0-9]*');

    //用户管理
    Route::get('users', 'UserController@index')->name('admin.user');
    Route::get('user/{id}', 'UserController@update')->where('id','[1-9][0-9]*');
    Route::get('user', 'UserController@store');
    //给用户设置角色
    Route::get('user/{id}/role', 'UserController@role')->where('id','[1-9][0-9]*');
});